package com.maxatime.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.maxatime.pojo.entity.SysRole;
import com.maxatime.dao.SysRoleMapper;
import com.maxatime.pojo.entity.SysUser;
import com.maxatime.service.ISysRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ssb
 * @since 2024-07-15
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Autowired
    SysRoleMapper sysRoleMapper;

    @Override
    public Map<String, Object> map(SysRole sysRole) {
        PageHelper.startPage(sysRole.getPageNum(),sysRole.getPageSize());
        List<SysRole> list = sysRoleMapper.list(sysRole);
        PageInfo<SysRole> pageinfo = new PageInfo<SysRole>(list);
        Map<String, Object> m = new HashMap<>();
        m.put("list", list);
        m.put("pageInfo", pageinfo);
        return m;
    }

    @Override
    public SysRole insertSelective(SysRole sysRole) {
        sysRole.setDelFlag("0");
        // 获取当前的日期和时间
        Date d = new Date(); // 获取当前时间
        sysRole.setCreateTime(d);
        sysRole.setUpdateTime(d);
        sysRoleMapper.insertSelective(sysRole);
        return null;
    }

    @Override
    public int deleteByPrimaryKey(Integer roleId) {
        sysRoleMapper.deleteByPrimaryKey(roleId);
        return 0;
    }

    @Override
    public SysRole find(int roleId) {
        return sysRoleMapper.find(roleId);
    }

    @Override
    public int updateByPrimaryKeySelective(SysRole sysRole) {
        sysRoleMapper.updateByPrimaryKeySelective(sysRole);
        return 0;
    }
}
